/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package net.stuffrepos.bricknetcenter.gui;

import java.net.URL;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 *
 * @author Eduardo H. Bogoni <eduardobogoni@gmail.com>
 */
public class Icons {

    private static Log log = LogFactory.getLog(Icons.class);

    public static Icon getIcon(String name) {
        String directory = (Icons.class.getPackage().getName() + ".icons").replace(".", "/");
        String filePath = directory + "/" + name;

        if (log.isTraceEnabled()) {
            log.trace("Icon path: " + filePath);
        }


        URL url = ClassLoader.getSystemResource(filePath);
        if (url == null) {
            throw new RuntimeException("File \"" + filePath + "\" not exist");
        }
        return new ImageIcon(url);
    }
}
